package com.springboot.application.model;

/**
 * @author zihong.zheng
 * @version 1.0
 * @date 2021/9/6
 * @time 1:02
 * @description
 */

import com.springboot.application.enums.UserResultCode;

import java.io.Serializable;

public  class UserResultBean<T> implements Serializable {
    private static final long serialVersionUID = 7020216546043912954L;
    private static final UserResultCode SUCCESS;
    private String resultCode;
    private String resultMsg;
    private T result;

    public UserResultBean() {
    }

    public UserResultBean(String resultCode, String resultMsg) {
        this.resultCode = resultCode;
        this.resultMsg = resultMsg;
        this.result = null;
    }

    public UserResultBean(String resultCode, String resultMsg, T result) {
        this.resultCode = resultCode;
        this.resultMsg = resultMsg;
        this.result = result;
    }

    public UserResultBean(UserResultCode resultCode) {
        this.resultCode = resultCode.getResultCode();
        this.resultMsg = resultCode.getResultMsg();
        this.result = null;
    }

    public UserResultBean(UserResultCode resultCode, Object... args) {
        this.resultCode = resultCode.getResultCode();
        this.resultMsg = String.format(resultCode.getResultMsg(), args);
        this.result = null;
    }

    public UserResultBean(UserResultCode resultCode, T result) {
        this.resultCode = resultCode.getResultCode();
        this.resultMsg = resultCode.getResultMsg();
        this.result = result;
    }

    public String getResultCode() {
        return this.resultCode;
    }

    public void setResultCode(String resultCode) {
        this.resultCode = resultCode;
    }

    public String getResultMsg() {
        return this.resultMsg;
    }

    public void setResultMsg(String resultMsg) {
        this.resultMsg = resultMsg;
    }

    public UserResultBean setResultCodeAndMsg(String resultCode, String resultMsg) {
        this.resultCode = resultCode;
        this.resultMsg = resultMsg;
        return this;
    }

    public T getResult() {
        return this.result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public boolean isSuccess() {
        return UserResultCode.SUCCESS.getRespCode().equals(this.resultCode);
    }

    static {
        SUCCESS = UserResultCode.SUCCESS;
    }
}
